package com.jiwei.system.controller;

import cn.yiban.open.Authorize;
import com.jiwei.system.utils.CookieUtil;
import com.jiwei.system.vo.ResultVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import java.io.IOException;

@Controller
@RequestMapping(value = "repair")
public class UserPageController {

    int i = 0;
    /**
     * 用于报修用户登录页面的加载
     * @return ModelAmdView对象，对应templates的实体html
     */
    @GetMapping(value = "login")
    public ModelAndView userLoginPage(HttpServletResponse response, HttpServletRequest request) throws IOException {
//        if(request.getParameter("verify_request")==null&&i==0){
//            Authorize au = new Authorize("387671be451b9bfd", "6e2792f78df7ce21eb3b850cba661296");
//            String url = au.forwardurl("http://f.yiban.cn/iapp674915", "QUERY", Authorize.DISPLAY_TAG_T.WEB);
//            request.getSession().setAttribute("userlogin", "13532522216");
//            response.sendRedirect(url);
//            return new ModelAndView("pages/User/repair/repair");
//        }
        return new ModelAndView("pages/User/user_login");
    }

    /**
     * 用户主页
     * @return ModelAmdView对象，对应templates的实体html
     */
    @GetMapping(value = "index")
    public ModelAndView userIndexPage(){
        return new ModelAndView("pages/User/repair/repair");
    }

    /**
     * 用户报修页面
     * @return ModelAmdView对象，对应templates的实体html
     */
    @GetMapping(value = "repair")
    public ModelAndView repairFormPage(){
        return new ModelAndView("pages/User/repair/repair");
    }

    /**
     * 用户报修历史页
     * @return ModelAmdView对象，对应templates的实体html
     */
    @GetMapping(value = "history")
    public ModelAndView RepairedFormPage(){
        return new ModelAndView("pages/User/history/history");
    }



    @GetMapping("quit")
    public String quit(HttpServletResponse response, HttpServletRequest request) throws IOException{
//        CookieUtil.removeUserCookie(response,"author_token");
          request.getSession().removeAttribute("login");
        request.getSession().removeAttribute("userlogin");
        return "redirect:login";
    }
}
